#!/bin/bash
set -e

GREEN="\033[32m"
YELLOW="\033[33m"
RED="\033[31m"
RESET="\033[0m"

echo -e "${GREEN}=================================${RESET}"
echo -e "${GREEN}  国内快速安装 Node.js + pnpm${RESET}"
echo -e "${GREEN}=================================${RESET}"

if [ "$EUID" -ne 0 ]; then
  echo -e "${RED}请用 root 用户执行${RESET}"
  exit 1
fi

yum install -y curl wget git >/dev/null 2>&1

NVM_DIR="/root/.nvm"
NVM_VERSION="v0.39.7"

# 用 Gitee 镜像安装 nvm
if [ ! -d "$NVM_DIR" ]; then
  echo -e "${YELLOW}安装 nvm...${RESET}"
  curl -o- https://gitee.com/mirrors/nvm/raw/${NVM_VERSION}/install.sh | bash
else
  echo -e "${YELLOW}nvm 已存在，跳过安装${RESET}"
fi

